package net.begincode.admin.controller;

import com.google.common.base.Preconditions;
import net.begincode.admin.bean.BlogHomeTypeParam;
import net.begincode.admin.bean.BlogKeyWordParam;
import net.begincode.biz.BlogBiz;
import net.begincode.common.ApiResponse;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;


/**
 * 博文关键字关系管理
 */
@Controller
@RequestMapping("admin/blogKeyWord")
public class BlogKeyWordController {

    @Resource
    private BlogBiz blogBiz;
    /**
     * 设置关键字
     * */
    @RequestMapping("/setKeyWords")
    @ResponseBody
    public ApiResponse<Boolean> setKeyWords(BlogKeyWordParam blogKeyWordParam) {
        Preconditions.checkNotNull(blogKeyWordParam, "blogKeyWordParam not null");
        blogKeyWordParam.checkParam();
        int returnValue = blogBiz.setBlogKeyWords(blogKeyWordParam.getBlogId(), blogKeyWordParam.getKeyWordIds());
        if (returnValue > 0) {
            return ApiResponse.success(true);
        }
        return ApiResponse.fail(false);
    }

    /**
     * 设置网站分类
     * */
    @RequestMapping("setHomeType")
    @ResponseBody
    public ApiResponse<Boolean> setHomeType(BlogHomeTypeParam blogHomeTypeParam) {
        Preconditions.checkNotNull(blogHomeTypeParam, "blogHomeTypeParam not null");
        blogHomeTypeParam.checkParam();
        int returnValue = blogBiz.setBlogHomeType(blogHomeTypeParam.getBlogId(), blogHomeTypeParam.getHomeTypeId());
        if (returnValue > 0) {
            return ApiResponse.success(true);
        }
        return ApiResponse.fail(false);
    }

}
